package com.diandiansong.manager.ui.user;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;

import com.diandiansong.app.R;
import com.diandiansong.app.entity.MessageInfo;
import com.diandiansong.manager.utils.M;

import java.util.List;

import diandiansong.library.ui.base.BaseAct;
import diandiansong.library.ui.base.FastListFragment;
import diandiansong.library.utils.CCallBack;

/**
 * 消息通知
 */
public class MsgList extends BaseAct {

    public static void start(Context context) {
        Intent starter = new Intent(context, MsgList.class);
        context.startActivity(starter);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initTitle("消息通知");

        addFragment(new SubFragment());
    }

    public static class SubFragment extends FastListFragment {
        @Override
        public int getItemLayoutRes() {
            return R.layout.msg_item;
        }

        @Override
        public void bindItemView(int position, @NonNull View convertView) {

            MessageInfo.Data item = (MessageInfo.Data) getItem(position);

            fastText(convertView, R.id.tv_date, item.getCreatetime());
            fastText(convertView, R.id.tv_msg, item.getContents());
        }

        /**
         * 滑到底部时调用
         */
        @Override
        protected void loadMore() {
            M.salesMessage(mPage, new CCallBack<MessageInfo>() {
                @Override
                public void onSuccess(MessageInfo o) throws Exception {
                    List<MessageInfo.Data> data = o.getData();
                    mAdapter.setData(data);
                    onLoadFinishNoMore();
                }

                @Override
                public void onFailure(int code, String msg) {
                    onLoadFinishNoMore();
                    toast(msg);
                }
            });
        }

        @Override
        public void onItemClick(Object o) {
            super.onItemClick(o);
        }
    }
}
